#!/usr/bin/env python
# coding=utf-8
# @Time    : 2021/12/26
# @Author  : 秋天的落寞

import os
from loguru import logger
from send_config import Device_config
from login_device import ssh_user_passwd, telnet_user_passwd, Login_device


def main_ssh():
    us_pa = ssh_user_passwd()
    with open('ip_list_ssh.txt', encoding='utf-8') as ip_list:
        if os.path.getsize("ip_list_ssh.txt") != 0:
            print("*" * 20 + ' SSH ' + "*" * 20)
            for ip_add in ip_list:
                con = Login_device(ip_add.strip(), us_pa[0], us_pa[1], 'hp_comware')
                if con is not None:
                    logger.info(f"[+] {ip_add.strip()} 登陆成功")
                    Device_config(con)


def main_telnet():
    us_pa = telnet_user_passwd()
    with open('ip_list_telnet.txt', encoding='utf-8') as ip_list:
        if os.path.getsize("ip_list_telnet.txt") != 0:
            print("*" * 20 + ' telnet ' + "*" * 20)
            for ip_add in ip_list:
                con = Login_device(ip_add.strip(), us_pa[0], us_pa[1], 'hp_comware_telnet')
                if con is not None:
                    logger.info(f"[+] {ip_add.strip()} 登陆成功")
                    Device_config(con)


def main():
    main_ssh()
    main_telnet()


if __name__ == "__main__":
    main()
